import { LayoutSiderAction, LayoutSiderActionTypes } from '../actions';

export interface LayoutSiderState {
    isCollapsed: boolean;
}

export const initialLayoutSiderState: LayoutSiderState = {
    isCollapsed: false
}

export function layoutSiderReducer(state: LayoutSiderState = initialLayoutSiderState, action: LayoutSiderAction): LayoutSiderState {
    switch(action.type) {
        case LayoutSiderActionTypes.SIDER_IS_COLLAPSED: {
            return {
                isCollapsed: action.payload
            }
        }
        case LayoutSiderActionTypes.SIDER_NOT_COLLAPSED: {
            return {
                isCollapsed: action.payload
            }
        }
        default: {
            return state;
        }
    }
}

export const getLayoutSiderIsCollapsed = (state: LayoutSiderState) => state.isCollapsed;